import DList from "@/components/dlist";
import searchBox from "./components/search_box.vue";
import bottomBar from "./components/bottom_bar.vue"
export default {
  data() {
    return {
      active: "2",
      classifyData: [],
      publishLists: {
        recommendCategory: [],
        nearby_shifu: [],
        carousel_images: []
      },
      myLocation: {},
      type: ""
    };
  },
  mounted() {
    this.myLocation = JSON.parse(localStorage.getItem("myLocation"));
  },
  activated() {
    this.type = this.$route.params.type ? this.$route.params.type + '' : '';
    this.active = this.$route.params.type ? this.$route.params.type + '' : '2';
    this.getClassifyData();
  },
  methods: {
    getData() {
      let form = {sort_type: this.active };
      let url = "plugin.be-within-call.frontend.index.tab-one";
      if(this.active == "2") {
        form = {
          lng: this.myLocation ? this.myLocation.point.lng : "",
          lat: this.myLocation ? this.myLocation.point.lat : "",
          sort_type: this.active
        }
        url = "plugin.be-within-call.frontend.index.tab-two"
      }else if(this.active == "3") {
        url = 'plugin.be-within-call.frontend.index.tab-three'
      }
      $http.get(url, { ...form }).then(({ data , result , msg }) => {
        if (result) {
          this.publishLists.recommendCategory = data.recommendCategory;
          this.publishLists.nearby_shifu = this.active == "2" ? data.nearby_shifu : [];
          this.publishLists.carousel_images = data.carousel_images;
          console.log(data,1111111);
        } else {
          this.$toast(msg);
        }
      });
    },
    // 获取分类
    getClassifyData() {
      $http.get("plugin.be-within-call.frontend.index.get-category-list", { sort_type: this.active }).then(({ data , result , msg }) => {
        if (result) {
          this.classifyData = this.splitArr(data,10);
          this.getData();
        } else {
          this.$toast(msg);
        }
      });
    },
    splitArr (arr,num) {
      var res=[];
      for (var i = 0,len = arr.length; i < len; i+=num) {
        res.push(arr.slice(i, i+num));
      }
      return res
    },
    goMoreList(id) {
      this.$router.push(
        this.fun.getUrl("anytimePublisherList", { type:this.active , id })
      );
    },
    // 跳转个人需求
    goividualNeeds(type,item) {
      console.log(item.order_id,'item.order_id');
      this.$router.push(
        this.fun.getUrl("anytimeIndividualNeeds", {type , order_id: item.id})
      );
    },
    // 跳转技师师傅主页
    goTechnicianHome(id) {
      this.$router.push(
        this.fun.getUrl("anytimeTechnicianHome", { id })
      );
    },
    changeTab(val) {
      this.getClassifyData();
    },
    tosearch() {
      this.$router.push(
        this.fun.getUrl("anytimeSearch", {name:'技师'})
      );
    }
  },
  components: { DList , searchBox , bottomBar}
};
